package com.lovo.pay.mq;

import com.lovo.common.util.MQUtil;
import com.lovo.pay.service.IPayService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@RabbitListener(queues = {"pay.direct.queue"})
public class PayReceiver {
    @Resource
    private IPayService payService;
    @Resource
    private MQUtil mqUtil;
    @RabbitHandler
    public void receive(String orderId, Message message, Channel channel){
        // 修改订单状态和库存
        try{
            payService.update(orderId);
            mqUtil.ack(message,channel);
        }catch(Throwable e){
            mqUtil.nack(message,channel);
        }
    }
}
